package com.zty.schedule.api;

import com.zty.schedule.entity.JsonResult;
import com.zty.schedule.entity.ValueRecord;
import com.zty.schedule.service.ValueRecordService;
import com.zty.schedule.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(description = "产值接口")
@RestController
@RequestMapping("ValueRecord")
@CrossOrigin
public class ValueRecordController {
    @Autowired
    private ValueRecordService valueRecordService;

    @ApiOperation(value = "增加产值",notes = "")
    @PostMapping("/InsertValueRecord")
    public JsonResult InsertValueRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i= valueRecordService.InsertValueRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("增加成功!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("增加失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除产值",notes = "")
    @PostMapping("/DeleteValueRecord")
    public JsonResult DeleteValueRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i= valueRecordService.DeleteValueRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("删除成功!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改产值",notes = "")
    @PostMapping("/UpdateValueRecord")
    public JsonResult UpdateValueRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i= valueRecordService.UpdateValueRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("修改成功!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页查询项目进度信息",notes = "")
    @PostMapping("/FindValueRecord")
    public Page FindValueRecord(@RequestBody Map map){
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(valueRecordService.Total());
        page.setItems(valueRecordService.FindValueRecord(map));
        return page;
    }
}
